package com.dennytech.tac.net.api;

import org.json.JSONException;
import org.json.JSONObject;

import android.text.TextUtils;

import com.dennytech.tac.net.BaseApi;

public class AttractionListApi extends BaseApi {

	private int start;
	private int length;
	private String keyword;
	private String ids;

	public void setStart(int start) {
		this.start = start;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public void setIds(String ids) {
		if ("".equals(ids)) {
			this.ids = "-1";
			return;
		} else {
			this.ids = ids;
		}
	}

	@Override
	public JSONObject query() {
		StringBuilder sb = new StringBuilder();
		sb.append(API_DOMAIN + "attractionlist.json?");

		if (start != 0) {
			sb.append("&s=" + start);
		}

		if (length != 0) {
			sb.append("&l=" + length);
		}

		if (!TextUtils.isEmpty(keyword)) {
			sb.append("&k=" + keyword);
		}

		if (!TextUtils.isEmpty(ids)) {
			sb.append("&ids=" + ids);
		}

		String bytes = getRawStr(sb.toString());
		if (bytes == null) {
			return null;
		}

		JSONObject object;

		try {
			object = new JSONObject(bytes);
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return object;
	}

}
